﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Dot5Demo.Frms
{
    public partial class FrmSettings : Form
    {

        public FrmSettings()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Load += FrmSettings_Load;
        }

        private Config conf;

        private void FrmSettings_Load(object sender, EventArgs e)
        {
            conf = AppContext.SoftConfiger;
            this.tableLayoutPanel1.RowStyles.Clear();
            var row = new RowStyle(SizeType.Absolute, 50f);
            var lb = new Label()
            {
                Text = "Language:"
            };
            this.tableLayoutPanel1.RowStyles.Add(row);
            this.tableLayoutPanel1.Controls.Add(lb, 0, 0);
            var cbx = new ComboBox()
            {
                DropDownStyle = ComboBoxStyle.DropDownList,
                Text = conf.Language,
                Width = 200,
            };
            this.tableLayoutPanel1.Controls.Add(cbx, 1, 0);

            cbx.DataSource = Config.GetAllLanguages();
            cbx.DisplayMember = "DisplayName";
            cbx.ValueMember = "Name";
            cbx.SelectedItem = ResourceExtensions.CultureInfo;
            cbx.SelectedIndexChanged += Cbx_SelectedIndexChanged;
        }

        private void Cbx_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item = (sender as ComboBox).SelectedItem;
            if(item is CultureInfo)
            {
                conf.Language = (item as CultureInfo).Name;
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            this.Close();
            AppContext.ApplyConfig();
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
